home comics writing pictures archive about

Set.cpp

Language: C++
Last Modified: 2022-09-10 5:29:28 PM UTC
File Size: 4729 bytes
http://www.penguinstew.ca/example/CodeFormater/Set.cpp
includeSeth
include<sstream>
include<regex>
includePhpHelperh
includeFormatHelperh
defineSET_COLOUR_ATTRIBUTEcolour
defineSET_REGEX_ATTRIBUTEregEx
defineSET_WILD_REGEX_ATTRIBUTEwildRegEx
defineSET_STARTTYPES_ELEMENTstartTypeIds
defineSET_STARTTYPE_ELEMENTstartType
defineSET_WORDS_ELEMENTwords
conststd::stringSet::SET_PATTERN_WORD=~word;
defineSET_PATTERN_WORD_LENGTH5
Set::SetxmlNodePtrxmlNode
{
colour=;
regExText=a^;
regEx=std::regexregExText;
wildRegExText=[azAZ09];
wildRegEx=std::regexwildRegExText;
words=std::vector<std::string>;
startIds=std::vector<TypeIdPair>;
xmlCharxmlString;
xmlNodePtrxmlChild=NULL;
xmlNodePtrxmlSubChild=NULL;
xmlString=xmlGetPropxmlNodexmlCharStrdupSET_COLOUR_ATTRIBUTE;
ifxmlString=NULL
{
colour=std::stringcharxmlString;
}
xmlString=xmlGetPropxmlNodexmlCharStrdupSET_REGEX_ATTRIBUTE;
ifxmlString=NULL
{
regExText=std::stringcharxmlString;
regEx=std::regexregExText;
}
xmlString=xmlGetPropxmlNodexmlCharStrdupSET_WILD_REGEX_ATTRIBUTE;
ifxmlString=NULL
{
wildRegExText=std::stringcharxmlString;
wildRegEx=std::regexwildRegExText;
}
forxmlChild=xmlNode>children;xmlChild=NULL;xmlChild=xmlChild>next
{
ifxmlChild>type=XML_ELEMENT_NODE{
continue;
}
ifxmlStrEqualxmlChild>namexmlCharStrdupSET_STARTTYPES_ELEMENT
{
forxmlSubChild=xmlChild>children;xmlSubChild=NULL;xmlSubChild=xmlSubChild>next
{
ifxmlChild>type=XML_ELEMENT_NODE{
continue;
}
ifxmlStrEqualxmlSubChild>namexmlCharStrdupSET_STARTTYPE_ELEMENT
{
TypeIdPairtypePair=TypeIdPairxmlSubChild;
startIdspush_backtypePair;
}
}
}
ifxmlStrEqualxmlChild>namexmlCharStrdupSET_WORDS_ELEMENT
{
xmlString=xmlNodeGetContentxmlChild;
ifxmlString=NULL
{
words=PhpHelper::explodestd::stringcharxmlString;
}
}
}
}
std::stringSet::GetColour
{
returnthis>colour;
}
std::regexSet::GetRegEx
{
returnthis>regEx;
}
std::regexSet::GetWildRegEx
{
returnthis>wildRegEx;
}
std::vector<std::string>Set::GetWords
{
returnthis>words;
}
std::vector<TypeIdPair>Set::GetStartIds
{
returnstartIds;
}
intSet::FindAndPrintSetWordstd::stringstreamlineStreamstd::stringlineintposTypeIdPairtestTypecharpreCStatecurrentState
{
ifstd::regex_matchstd::string1preCregEx
{
return0;
}
boolmatch=false;
forunsignedinti=0;i<startIdssize;i
{
TypeIdPairti=startIdsati;
iftiIsMatchtestType
{
match=true;
break;
}
}
ifmatch
{
return0;
}
std::stringword;
std::stringwildCardWord;
std::stringfoundWord;
forunsignedinti=0;i<wordssize;i
{
word=wordsati;
size_twildcardPos=wordfindSET_PATTERN_WORD;
ifwildcardPos=std::string::npos
{
ifwildcardPos=0
{
wildCardWord=wordsubstr0wildcardPos;
ifFormatHelper::IsMatchlinewildCardWordposregEx
{
wildCardWordappendFormatHelper::GetWordlineposwildcardPoswildRegEx;
foundWord=wildCardWord;
break;
}
}
else
{
foundWord=FormatHelper::GetWordlineposregEx;
break;
}
}
ifFormatHelper::IsMatchlinewordposregEx
{
foundWord=word;
break;
}
}
intwordLength=foundWordlength;
ifwordLength>0
{
ifcurrentStateGetId=0
{
currentStatePrintCloselineStream;
}
std::stringcleanWord=PhpHelper::htmlspecialcharsfoundWord;
lineStream<<<spanclass=\<<colour<<\><<cleanWord<<<span>;
ifcurrentStateGetId=0
{
currentStatePrintRestartlineStream;
}
returnwordLength;
}
return0;
}
std::stringSet::ToString
{
std::stringstreamstream;
stream<<Set:;
stream<<Colour:<<this>colour<<;
stream<<RegEx:<<this>regExText<<std::endl;
stream<<WildRegEx:<<this>wildRegExText<<std::endl;
stream<<Words<<std::endl;
forunsignedinti=0;i<wordssize;i
{
stream<<wordsati<<std::endl;
}
stream<<StartIDs<<std::endl;
forunsignedinti=0;i<startIdssize;i
{
TypeIdPairpair=startIdsati;
stream<<pairToString<<std::endl;
}
returnstreamstr;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208